package com.bom_samaritano.dao;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;

import com.bom_samaritano.model.Person;
import com.bom_samaritano.model.Route;

public class DBHelper extends SQLiteOpenHelper {

	private static final String DATABASE_NAME = "samaritano.db";
	private static final int DATABASE_VERSION = 1;

	DBHelper(Context context) {
		super(context, DATABASE_NAME, null, DATABASE_VERSION);
	}

	@Override
	public void onCreate(SQLiteDatabase db) {

		db.execSQL("CREATE TABLE IF NOT EXISTS " + Person.TABLE + " ( "
				+ Person.COL_ID + " INTEGER  NOT NULL , " + Person.COL_NAME
				+ " VARCHAR(20) NULL," + Person.COL_EMAIL
				+ " VARCHAR(20) NULL, " + Person.COL_PHONE + " INTEGER NULL, "
				+ Person.COL_HAS_CAR + " VARCHAR(20) NULL, " + Person.COL_LOGIN
				+ " VARCHAR(20) NULL, " + Person.COL_SENHA
				+ " BIT NULL, PRIMARY KEY(" + Person.COL_ID + " ASC) );");

		System.out.println("CREATE TABLE teste");

		Log.println(0, "DEBUG", " tabela pessoa ok");
		db.execSQL("CREATE TABLE IF NOT EXISTS " + Route.TABLE + "( "
				+ Route.COL_ID + " INTEGER  NOT NULL , " + Route.COL_NAME
				+ " VARCHAR(20) NULL, " + Route.COL_OWNER
				+ " INTEGER  NOT NULL, " + Route.COL_LATITUDES + " TEXT NULL, "
				+ Route.COL_LONGITUDES + " TEXT NULL," + Route.COL_VACANCY
				+ " INTEGER  NULL, " + " PRIMARY KEY(" + Route.COL_ID
				+ " ASC), FOREIGN KEY(" + Route.COL_OWNER + ") REFERENCES "
				+ Person.TABLE + "(" + Person.COL_EMAIL + ") );");
		Log.println(0, "DEBUG", " tabela rota ok");
	}

	@Override
	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
		throw new UnsupportedOperationException();
	}
}